import axios from 'axios';
import {message} from 'antd';

let Axios = axios.create({
    baseURL:'/hdu',
    timeout:10000,
    withCredentials: true,
/*  transformRequest: [function(data) {
        data = JSON.stringify(data);
            return data;
    }]
    */
});

Axios.interceptors.request.use( function (config) {
    if (localStorage.token) {
        config.headers.Authorization = 'Bearer ' + localStorage.token; //token类型为OAuth 2.0
    }
    return config;
}, function (error) {
    return Promise.reject(error);
});

Axios.interceptors.response.use(function (res){
    if (res.data.code === 0 ) {
        message.info('用户登录状态过期');
        window.location.href='http://localhost:3333/';
    }
    return res;
}, function (error) {
    return Promise.reject(error);
});

export default Axios;
